package app.species;

import java.io.Serializable;
import sim.util.*;
import ec.util.*;

public class SpawnPoint implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4925563280473716442L;
	private double centerX, centerY;
	private double minDistCenter, maxDistCenter;

	public SpawnPoint(double cx, double cy, double min, double max){

		this.centerX = cx;
		this.centerY = cy;
		this.minDistCenter = min;
		this.maxDistCenter = max;

	}

	/* returns a random location within the spawn area
	 **/
	public MutableDouble2D getRandomLocation(MersenneTwisterFast random){

		MutableDouble2D position;

		/* find an initial position for the creature
		 **/
		while(true){

			position = new MutableDouble2D(random.nextDouble() * this.maxDistCenter, random.nextDouble() * this.maxDistCenter);

			if(position.length() >= this.minDistCenter && position.length() <= this.maxDistCenter) break;

		}

		if(random.nextBoolean()) position.x *= -1.0;
		if(random.nextBoolean()) position.y *= -1.0;

		position.addIn(this.centerX, this.centerY);

		return position;

	}

}
